package com.terminus.test;

import com.terminus.test.cipher.Cipherer;
import com.terminus.test.filter.BloomFilter;
import com.terminus.test.multi.Count;
import com.terminus.test.multi.VisitThread;
import com.terminus.test.split.SplitUtil;

import java.time.Instant;
import java.util.Date;
import java.util.concurrent.ExecutorService;

public class Main {
    private static BloomFilter bloomFilter=new BloomFilter(4,0.001);
    private static String baseUrl="http://blog.csdn.net/lushuaiyin/article/details/";
    private static final int max=10000;
    public static void main(String[] args) throws InterruptedException {
        StringBuilder builder=new StringBuilder();
        ExecutorService executorService=Count.getExecutorService();

        Count.setLimit(max);
        Count.setStart(Date.from(Instant.now()).getTime());

        for (int i = 0; i <max ; i++) {
            builder.setLength(0);
            long offset= Math.round(Math.random()*Integer.MAX_VALUE);
            builder.append(baseUrl).append(offset);
            executorService.execute(new VisitThread(bloomFilter,builder.toString()));
        }
        System.out.println(Date.from(Instant.now()).getTime()-Count.getStart());
    }

    public static void visitedTest(){
        long start=Date.from(Instant.now()).getTime();
        int visitedCnt=0;
        int unvisitedCnt=0;
        StringBuilder builder=new StringBuilder();
        for (int i = 0; i <100000 ; i++) {
            builder.setLength(0);
            long offset= Math.round(Math.random()*Integer.MAX_VALUE);
            builder.append(baseUrl).append(offset);
            if(bloomFilter.isVisited(builder.toString())){
                visitedCnt++;
            }else {
                unvisitedCnt++;
            }
        }
        System.out.println(Date.from(Instant.now()).getTime()-start);
        System.out.println("unvisitedCnt: "+unvisitedCnt+"\tvisitedCnt:\t"+visitedCnt);
    }
}
